﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<InternshipManagement.Models.UserPriviligeModel>" %>

<%@ Import Namespace="InternshipManagement.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    User Privileges
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm())
       { %>
    <table id="userprivilege">
        <tr>
            <th>
            </th>
            <th>
                Secretary
            </th>
            <th>
                Company
            </th>
            <th>
                Student
            </th>
        </tr>
        <% foreach (Privilege p in Model.Privileges)
           { %>
        <tr>
            <td style="background-color: #FFC; width: 275px">
                <%= p.Name%>
            </td>
            <td class="privilege">
                <%: Html.Hidden("Secretary-" + p.ID,Model.SecretaryPrivileges.Contains(p.ID)) %>
            </td>
            <td class="privilege">
                <%: Html.Hidden("Company-" + p.ID, Model.CompanyPrivileges.Contains(p.ID))%>
            </td>
            <td class="privilege">
                <%: Html.Hidden("Student-" + p.ID,Model.StudentPrivileges.Contains(p.ID)) %>
            </td>
        </tr>
        <%} %>
    </table>
    <p style="margin-left:50px">
        <input type="submit" value="Save" />
    </p>
    <%} %>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.privilege').each(function () {
                $(this).click(function () {
                    if ($(this).children('input:hidden').val() == "True") {
                        $(this).removeClass('checked');
                        $(this).children('input:hidden').val("False");
                    }
                    else {
                        $(this).addClass('checked');
                        $(this).children('input:hidden').val("True");
                    }
                });
                if ($(this).children('input:hidden').val() == "True") {
                    $(this).addClass('checked');
                }
                else {
                    $(this).removeClass('checked');
                }
            });
        });
    </script>
</asp:Content>
